package com.example.feitiansys.controller;

import com.example.feitiansys.pojo.Attendance;
import com.example.feitiansys.service.attendance.AttendanceService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpSession;
import java.util.Date;
import java.util.List;

@Controller
public class AttendanceController {
    @RequestMapping("/system/attend")
    public String attendshow(){
        return  "/system/attend/attend";
    }
    @RequestMapping("/system/attend/add")
    public String toadd(){
        return "/system/attend/add";
    }
    @RequestMapping("/system/attend/update")
    public String toupdate(){
        return "/system/attend/update";
    }
    @Autowired
    AttendanceService attendanceService;
    @RequestMapping("/system/attend/getAttend")
    @ResponseBody
    public Object selectAttend(Attendance attendance){
        if(attendance==null){
            attendance=new Attendance();
        }
    return attendanceService.queryAll(attendance);
    }
    @RequestMapping("/system/attend/getattendbyid")
    @ResponseBody
    public Object getattendbyid(Integer id){
        return attendanceService.queryById(id);
    }
    @RequestMapping("/system/attend/doadd")
    @ResponseBody
  public int  attenddoadd(Attendance attendance){
      Date date=new Date();
      attendance.setCreateTime(date);
      int insert=attendanceService.insert(attendance);
      return insert;
  }
  @RequestMapping("/system/attend/doupdate")
  @ResponseBody
  public Object attendupdate(Attendance attendance){
        return attendanceService.update(attendance);
  }
  @RequestMapping("/system/attend/delect")
  @ResponseBody
  public Object removeattend(Integer id){
        return attendanceService.deleteById(id);
  }

  @RequestMapping("/system/attend/todelect")
  @ResponseBody
  public Object removeattend(String array){
      String[] split = array.split(",");
      System.out.println(array+"----------------------");
      return attendanceService.deleteByIds(split);
  }

}
